<html> 
<head> 
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Nonresidential Cooling and Heating Calculations</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript" src="js/math_function.js"></script>
<script type="text/javascript" src="http://dimok911.net63.net/google_map.js"></script> 
<script type="text/javascript" src="js/sun.js"></script>
<script type="text/javascript" src="js/x_time_series.js"></script>
<script type="text/javascript" src="js/language.js"></script>
<script type="text/javascript" src="js/interpolate.js"></script>
<script type="text/javascript" src="js/base.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/charts.js"></script>
<script type="text/javascript"> 

var fraction_t = "0 0.88 0.92 0.95 0.98 1.00 0.98 0.91 0.74 0.55 0.38 0.23 0.13 0.05 0 0 0.06 0.14 0.24 0.39 0.5 0.59 0.68 0.75 0.82";

var RTS = "49 17 9 5 3 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0";
var RTS_2 = "54 16 8 4 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0";
var SHGC_fi = {0:0.49, 40:0.46, 50:0.44, 60:0.39, 70:0.31, 80:0.17, 90:0};
var fraction_t_array = new Array();
var RTS_array = new Array();
var RTS_array_2 = new Array();
fraction_t_array=fraction_t.split(" ");
RTS_array = RTS.split(" ");
RTS_array_2 = RTS_2.split(" ");
var language = 'ru';
var d = new Array();
var quantity_wall;
var quantity_window;
var quantity_roof;
var quantity_floor;
var cooling_load_walls = new Array();
var t_hour = new Array();



function request_place(location){
var params = "lat="+location.lat().toFixed(3)+"&long="+location.lng().toFixed(3)+"&number="+document.getElementById('number').value;
var request = new ajaxRequest();
request.open("POST", "http://dimok911.net63.net/request_places.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
deleteOverlays_near();
request.onreadystatechange = function()
	{
		if (this.readyState == 4) 
		{
			if (this.status == 200) 
			{
				if (this.responseText != null)
				{
				var meteo_response = this.responseText;
				var finish = meteo_response.indexOf('<');
				var json_string = meteo_response.slice(0,finish);
				var myplaces = json_string;
                myplaces = eval('(' + json_string + ')');
				for (var i=0; i<myplaces.meteo_stations.length; i++){
				var location_station = new google.maps.LatLng(myplaces.meteo_stations[i].lat, myplaces.meteo_stations[i].long);
				addMarker_near(location_station,location,myplaces.meteo_stations[i].place,(myplaces.meteo_stations[i].tt*6371).toFixed(0),i);
				}
				}
				else 
				alert("error Ajax: нету данных")
			}
			else
			alert("error Ajax:" + this.statusText)
		}
		
		
	}
	
request.send(params);
}


function ajaxRequest()
{
var request = new XMLHttpRequest();
return request;
}
//Add wall for calculation
function add_element(quantity,element){

    switch(element)
{
case 'wall':
  quantity_wall = quantity;
  break;
case 'window':
  quantity_window = quantity;
  break;
case 'roof':
  quantity_roof = quantity;
  break;
case 'floor':
  quantity_floor = quantity;
  break;
}
    var wall_number_CTS_x="";
	var psi_x="";
    var tilt_x="";
    var k_x="";
    var s_x="";
    var shgc_fi_x="";
    var shgc_d_x="";
    var iac_x="";
    var element_parameter;
    var title = new Array();
    title[0] = " _ ";
    var bottom_title="<td></td>";
        for (var j=1; j<quantity; j++){//Save previous values and generate rows
            title[j] = element + " " + j + "_"+element + " " + j ; //Create title names
			if (element=='wall'){
            wall_number_CTS_x = wall_number_CTS_x + "<td><div style=cursor:hand id ='"+"replace_" +element +"_" + j + "_CTS" +"' onClick=generate_table_CTS('"+element +"'," + j + ",'CTS')>" +document.getElementById("replace_" + element + "_" + j + "_CTS").innerHTML + "</div><div id=dialog_" + element+"_"+j+ "_CTS" + " title=Выбор><div id = " + element+ "_" + j +"_CTS></div></div></td>";
			}
            psi_x = psi_x + "<td> <input id="+element+"_psi_" + j + " type=textbox value=" + document.getElementById(element+"_psi_"+j).value + "></td>";
            tilt_x =  tilt_x + "<td> <input id="+ element+"_tilt_" + j + " type=textbox value=" + document.getElementById(element+"_tilt_"+j).value + "></td>";
            k_x = k_x + "<td> <input id="+element+"_k_" + j + " type=textbox value=" + document.getElementById(element+"_k_"+j).value + "></td>";
            s_x = s_x + "<td> <input id="+element+"_s_" + j + " type=textbox value=" + document.getElementById(element+"_s_"+j).value + "></td>";
            bottom_title = bottom_title + "<td><input type=button value='Удалить " + element + "' onclick=delete_element("+j+",'" + element + "')></td>";
        if (element=='window'){
                shgc_fi_x = shgc_fi_x + "<td> <input id="+element+"_shgc_fi_" + j + " type=textbox value=" + document.getElementById(element+"_shgc_fi_"+j).value + "></td>";
                shgc_d_x = shgc_d_x + "<td> <input id="+element+"_shgc_d_" + j + " type=textbox value=" + document.getElementById(element+"_shgc_d_"+j).value + "></td>";
                iac_x = iac_x + "<td> <input id="+element+"_iac_" + j + " type=textbox value=" + document.getElementById(element+"_iac_"+j).value + "></td>";
            }
		}
            
             
        //Add new column
        title[quantity] = element + "" + quantity +"_TR" + quantity;
	    wall_number_CTS_x = wall_number_CTS_x + "<td><div style=cursor:hand id ='"+"replace_" +element +"_" + j + "_CTS" +"' onClick=generate_table_CTS('"+element +"'," + j + ",'CTS')><u>Выбор стены...</u></div><div id=dialog_" + element+"_"+j+ "_CTS" + " title=Выбор><div id = " + element + "_" + j +"_CTS></div></div></td>";
        psi_x = psi_x + "<td> <input id="+element+"_psi_" + quantity + " type=textbox value=60></td>";
        tilt_x =  tilt_x + "<td> <input id="+element+"_tilt_" + quantity + " type=textbox value=90></td>";
        k_x = k_x + "<td> <input id="+element+"_k_" + quantity + " type=textbox value=0.45></td>";
        s_x = s_x + "<td> <input id="+element+"_s_" + quantity + " type=textbox value=11.15></td>";
        bottom_title = bottom_title + "<td><input type=button value='Удалить " + element + "' onclick=delete_element("+ quantity + ",'" + element +"')></td>";
           if (element=='window'){
                shgc_fi_x = shgc_fi_x + "<td> <input id="+element+"_shgc_fi_" + quantity + " type=textbox value=0.3978></td>";
                shgc_d_x = shgc_d_x + "<td> <input id="+element+"_shgc_d_" + quantity + " type=textbox value=0.41></td>";
                iac_x = iac_x + "<td> <input id="+element+"_iac_" + quantity + " type=textbox value=1></td>";
            }
//Generate table with new column       
if (element=='wall'){
element_parameter = "<b>" + element + "<b><table>" + create_table_titles(title)+ "<tr><td>Тип стены</td>" + wall_number_CTS_x +"<td><input type=button value=Добавить стену onclick=add_element(" + (quantity*1+1) + ",'"+element+ "')></td></tr><tr><td>Ориентация поверхности( Юг-0, + - на запад)</td>" + psi_x + "</tr><tr><td>Наклон поверхности к горизонтали</td>" + tilt_x + "</tr><tr><td>Коэффициент теплопередачи стены</td>" + k_x + "</tr><tr><td>Площадь стены</td>" + s_x + "</tr><tr>" + bottom_title + "</tr></table>";
};
if (element=='window') { 
    element_parameter = "<b>" + element + "<b><table>" + create_table_titles(title)+ "<tr><td>Ориентация поверхности( Юг-0, + - на запад)</td>" + psi_x + "<td><input type=button value=Добавить окно onclick=add_element(" + (quantity*1+1) + ",'"+element+ "')></td></tr><tr><td>Наклон поверхности к горизонтали</td>" + tilt_x + "</tr><tr><td>Коэффициент теплопередачи окна</td>" + k_x + "</tr><tr><td>Площадь окна</td>" + s_x + "</tr><tr><td>SHGC_fi</td>" + shgc_fi_x + "</tr><tr><td>SHGC_d</td>" + shgc_d_x + "</tr><tr><td>IAC</td>" + iac_x + "</tr><tr>" + bottom_title + "</tr></table>";

}
    document.getElementById(element).innerHTML = element_parameter;
	if (document.getElementsByName('group1')[0].checked){
	solar_irradiance_select();
	}
	else {
	cooling_load_element_select();
	}
	
}

//Delete element
function delete_element(number_element,element){
    var quantity;
     switch(element)
{
case 'wall':
  quantity_wall = quantity_wall - 1;
  quantity = quantity_wall;
  break;
case 'window':
  quantity_window = quantity_window - 1;
  quantity = quantity_window;
  break;
case 'roof':
  quantity_roof = quantity_roof - 1;
  quantity = quantity_roof;
  break;
case 'floor':
  quantity_floor = quantity_floor - 1;
  quantity = quantity_floor;
  break;
}
    var wall_number_CTS_x="";
    var psi_x="";
    var tilt_x="";
    var k_x="";
    var s_x="";
	var shgc_fi_x="";
    var shgc_d_x="";
    var iac_x="";
	var element_parameter;
    var title = new Array();
    title[0] = " _ ";
    var bottom_title="<td></td>";
    
     
        
    for (var j=1; j<=(quantity+1); j++){
	title[j] = element + " " + j + "_"+element + " " + j ; //Create title names
 
        
        if (j < number_element){
		  if (element=='wall'){
        wall_number_CTS_x = wall_number_CTS_x + "<td><div style=cursor:hand id ='"+"replace_" +element +"_" + j + "_CTS" +"' onClick=generate_table_CTS('"+element +"'," + j + ",'CTS/)>" +document.getElementById("replace_" + element + "_" + j + "_CTS").innerHTML + "</div><div id=dialog_" + element+"_"+j+ "_CTS" + " title=Выбор><div id = " + element+ "_" + j +"_CTS></div></div></td>";
			}
            psi_x = psi_x + "<td> <input id="+element+"_psi_" + j + " type=textbox value=" + document.getElementById(element+"_psi_"+j).value + "></td>";
            tilt_x =  tilt_x + "<td> <input id="+ element+"_tilt_" + j + " type=textbox value=" + document.getElementById(element+"_tilt_"+j).value + "></td>";
            k_x = k_x + "<td> <input id="+element+"_k_" + j + " type=textbox value=" + document.getElementById(element+"_k_"+j).value + "></td>";
            s_x = s_x + "<td> <input id="+element+"_s_" + j + " type=textbox value=" + document.getElementById(element+"_s_"+j).value + "></td>";
             bottom_title = bottom_title + "<td><input type=button value='Удалить " + element + "' onclick=delete_element("+j+",'" + element + "')></td>";
			if (element=='window'){
                shgc_fi_x = shgc_fi_x + "<td> <input id="+element+"_shgc_fi_" + j + " type=textbox value=" + document.getElementById(element+"_shgc_fi_"+j).value + "></td>";
                shgc_d_x = shgc_d_x + "<td> <input id="+element+"_shgc_d_" + j + " type=textbox value=" + document.getElementById(element+"_shgc_d_"+j).value + "></td>";
                iac_x = iac_x + "<td> <input id="+element+"_iac_" + j + " type=textbox value=" + document.getElementById(element+"_iac_"+j).value + "></td>";
            }
        }
        if (j > number_element){
		if (element=='wall'){
		wall_number_CTS_x = wall_number_CTS_x + "<td><div style=cursor:hand id ='"+"replace_" +element +"_" + (j-1) + "_CTS" +"' onClick=generate_table_CTS('"+element +"'," + (j-1) + ",'CTS')>" +document.getElementById("replace_" + element + "_" + j + "_CTS").innerHTML + "</div><div id=dialog_" + element+"_"+(j-1)+ "_CTS" + " title=Выбор><div id = " + element+ "_" + (j-1) +"_CTS></div></div></td>";
            }
             psi_x = psi_x + "<td> <input id="+element+"_psi_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_psi_"+j).value + "></td>";
            tilt_x =  tilt_x + "<td> <input id="+ element+"_tilt_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_tilt_"+j).value + "></td>";
            k_x = k_x + "<td> <input id="+element+"_k_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_k_"+j).value + "></td>";
            s_x = s_x + "<td> <input id="+element+"_s_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_s_"+j).value + "></td>";
             bottom_title = bottom_title + "<td><input type=button value='Удалить " + element + "' onclick=delete_element("+(j-1)+",'" + element + "')></td>";
			if (element=='window'){
                shgc_fi_x = shgc_fi_x + "<td> <input id="+element+"_shgc_fi_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_shgc_fi_"+j).value + "></td>";
                shgc_d_x = shgc_d_x + "<td> <input id="+element+"_shgc_d_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_shgc_d_"+j).value + "></td>";
                iac_x = iac_x + "<td> <input id="+element+"_iac_" + (j-1) + " type=textbox value=" + document.getElementById(element+"_iac_"+j).value + "></td>";
            }
        }
    }
	title.splice(-1,1);//Delete last title name
	if (quantity != 0){
	if (element=='wall'){
         element_parameter = "<b>" + element + "<b><table>" + create_table_titles(title)+ "<tr><td>Тип стены</td>" + wall_number_CTS_x + "<td><input type=button value=Добавить стену onclick=add_element(" + (quantity*1+1) + ",'"+element+ "')></td><tr><td>Ориентация поверхности( Юг-0, + - на запад)</td>" + psi_x + "</tr><tr><td>Наклон поверхности к горизонтали</td>" + tilt_x + "</tr><tr><td>Коэффициент теплопередачи стены</td>" + k_x + "</tr><tr><td>Площадь стены</td>" + s_x + "</tr><tr>" + bottom_title + "</tr></table>";
    }
	if (element=='window') { 
	     element_parameter = "<b>" + element + "<b><table>" + create_table_titles(title)+ "<tr><td>Ориентация поверхности( Юг-0, + - на запад)</td>" + psi_x + "<td><input type=button value=Добавить окно onclick=add_element(" + (quantity*1+1) + ",'"+element+ "')></td></tr><tr><td>Наклон поверхности к горизонтали</td>" + tilt_x + "</tr><tr><td>Коэффициент теплопередачи окна</td>" + k_x + "</tr><tr><td>Площадь окна</td>" + s_x + "</tr><tr><td>SHGC_fi</td>" + shgc_fi_x + "</tr><tr><td>SHGC_d</td>" + shgc_d_x + "</tr><tr><td>IAC</td>" + iac_x + "</tr><tr>" + bottom_title + "</tr></table>";
    }}
	else {
	element_parameter = ""
	}
	document.getElementById(element).innerHTML = element_parameter;
	if (document.getElementsByName('group1')[0].checked){
	solar_irradiance_select();
	}
	else {
	cooling_load_element_select();
	}


}
            

    


//Create buttons with wall_number to calculate solar irradiance
function solar_irradiance_select(){
    button_element_solar_irradiance = "";
    for (var i=1;i<=quantity_wall;i++){
        button_element_solar_irradiance = button_element_solar_irradiance + "<input type=button value=Стена" + i + " onclick=solar_irradiance('wall','"+ i + "')>";
    }    
	    for (var i=1;i<=quantity_window;i++){
        button_element_solar_irradiance = button_element_solar_irradiance + "<input type=button value=Окно" + i + " onclick=solar_irradiance('window','"+ i + "')>";
    }    
    document.getElementById("Table_qii").innerHTML = button_element_solar_irradiance;
}
    
    
    
//Generate solar irraiance table for wall with wall_number

function solar_irradiance(element,number){
    var h_string = button_element_solar_irradiance;
    var day_number = document.getElementById("day_number").value*1; try {if (day_number*1<0 || day_number*1>367) throw new Error("В году 365-366 дней")} catch(e) {document.getElementById("Table_qii").innerHTML = '';alert(e);return}
    var latitude = document.getElementById("latitude").value*1;
	var tout_design = document.getElementById("tout").value*1;
	var tout_range = document.getElementById("tout_range").value*1;
    var longitude = document.getElementById("longitude").value*1;
    var zone = document.getElementById("zone").value*1;
    var psi = document.getElementById(element+"_psi_"+number).value*1;
    var tilt = document.getElementById(element+"_tilt_"+number).value*1;
    var taub = document.getElementById("taub").value*1;
    var taud = document.getElementById("taud").value*1;
    var gr_rf = document.getElementById("gr_rf").value*1;
    var alfa_h0 = document.getElementById("alfa_h0").value*1;
    var epsilon_deltaR_h0 = document.getElementById("epsilon_deltaR_h0").value*1;
    d.length = 0;
	var bottom_line="";
    //Titles for table colums
        d[0] = "Local Standart Hour_Локальное время";
        d[1] = 'Apparent Solar Time_Действительное солнечное время';
        d[2] = "Hour Angle H_Часовой угол ч";
        d[3] = "Solar Altitude β_Высота солнца β";
        d[4] = "Solar Azimuth φ_Солнечный азимут φ";
        d[5] = "Beam Normal Eb,W/m2_Прямая радиация на нормаль, Вт/м2";
        d[6] = "Surface Incidence Angle_Угол падения на поверхность";
        d[7] = "Surface Direct W/m2_Прямая радиация на поверхность, Вт/м2";
        d[8] = "Diffuse Horizontal Ed,W/m2_Рассеянная радиация на горизонталь, Вт/м2";
        d[9] = "Ground Diffuse, W/m2_Отраженная от земли радиация, Вт/м2";
        d[10] = "Y Ratio_Коэффициент Y";
        d[11] = "Sky Diffuse, W/m2_Рассеянная радиация на поверхность, Вт/м2";
        d[12] = "Subtotal diffuse W/m2_Суммарная рассеянная радиация, Вт/м2";
        d[13] = "Total Surface Irradiance, W/m2_Полная радиация, Вт/м2";

    for (i=1; i<=24; i++){
    var myrad = new radiation(day_number, i, latitude, longitude, zone, psi, tilt, taub, taud, gr_rf,'' , alfa_h0, epsilon_deltaR_h0); 
    if (mysun_on_plane.aST>=0){
    t_hour[i] = tout_design - fraction_t_array[(mysun_on_plane.aST).toFixed(0)+1]*tout_range;   }
    else {    t_hour[i] = tout_design - fraction_t_array[25 - (mysun_on_plane.aST).toFixed(0)]*tout_range;   }	
    h_string +=  "<tr><td>" + i + "</td><td>" + mysun_on_plane.aST.toFixed(2) + "</td><td>" + mysun_on_plane.h.toFixed(0) + "</td><td>" + mysun_on_plane.beta.toFixed(0) + "</td><td>" + mysun_on_plane.fi.toFixed(0) + "</td><td>" + myrad.eb.toFixed(1) + "</td><td>" + mysun_on_plane.Fi.toFixed(1) + "</td><td>" + myrad.etb.toFixed(1) + "</td><td>" + myrad.ed.toFixed(1) + "</td><td>" + myrad.etr.toFixed(1) + "</td><td>" + myrad.y.toFixed(4) + "</td><td>" + myrad.etd.toFixed(1) + "</td><td>" + (myrad.estd).toFixed(1) + "</td><td>" + myrad.et.toFixed(1) + "</td></tr>";
	
}

bottom_line = "<td></td><td><input type=button value=График onclick=\"drawChart('sun','aST','"+element+"',"+number+",'"+d[1].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_aST_graph1><div id = " + element+ "_" + number +"_aST_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('sun','h','"+element+"',"+number+",'"+d[2].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_h_graph1><div id = " + element+ "_" + number +"_h_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('sun','beta','"+element+"',"+number+",'"+d[3].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_beta_graph1><div id = " + element+ "_" + number +"_beta_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('sun','fi','"+element+"',"+number+",'"+d[4].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_fi_graph1><div id = " + element+ "_" + number +"_fi_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','eb','"+element+"',"+number+",'"+d[5].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_eb_graph1><div id = " + element+ "_" + number +"_eb_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('sun','Fi','"+element+"',"+number+",'"+d[6].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_Fi_graph1><div id = " + element+ "_" + number +"_Fi_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','etb','"+element+"',"+number+",'"+d[7].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_etb_graph1><div id = " + element+ "_" + number +"_etb_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','ed','"+element+"',"+number+",'"+d[8].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_ed_graph1><div id = " + element+ "_" + number +"_ed_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','etr','"+element+"',"+number+",'"+d[9].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_etr_graph1><div id = " + element+ "_" + number +"_etr_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','y','"+element+"',"+number+",'"+d[10].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_y_graph1><div id = " + element+ "_" + number +"_y_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','etd','"+element+"',"+number+",'"+d[11].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_etd_graph1><div id = " + element+ "_" + number +"_etd_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','estd','"+element+"',"+number+",'"+d[12].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_estd_graph1><div id = " + element+ "_" + number +"_estd_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','et','"+element+"',"+number+",'"+d[13].split("_")[0]+"','sun')\"><div id = dialog_" + element+ "_" + number +"_et_graph1><div id = " + element+ "_" + number +"_et_graph2></div></div></td>";



document.getElementById("Table_qii").innerHTML = "<table border = 1>"+create_table_titles(d)+""+h_string+"<tr>" + bottom_line + "</tr></table>";
}

function cooling_load_element_select(){
    button_element_cooling_load = "";
    for (var i=1;i<=quantity_wall;i++){
        button_element_cooling_load = button_element_cooling_load + "<input type=button value=Стена" + i + " onclick=cooling_load_element('wall','"+ i + "',1)>";
    }
	    for (var i=1;i<=quantity_window;i++){
        button_element_cooling_load = button_element_cooling_load + "<input type=button value=Окно" + i + " onclick=cooling_load_element('window','"+ i + "',1)>";
    }
        button_element_cooling_load = button_element_cooling_load + "<input type=button value=Суммарная onclick=total_cooling_load_building()>";
    document.getElementById("Table_qii").innerHTML = button_element_cooling_load;
}


function cooling_load_element(element,number,table){//Generate cooling load table
       var h_string = button_element_cooling_load;
    var day_number = document.getElementById("day_number").value*1;
    var latitude = document.getElementById("latitude").value*1;
    var longitude = document.getElementById("longitude").value*1;
    var zone = document.getElementById("zone").value*1;
	var tout_design = document.getElementById("tout").value*1;
	var tout_range = document.getElementById("tout_range").value*1;
    var psi = document.getElementById(element + "_psi_" + number).value*1;
    var tilt = document.getElementById(element + "_tilt_" + number).value*1;
    var taub = document.getElementById("taub").value*1;
    var taud = document.getElementById("taud").value*1;
    var gr_rf = document.getElementById("gr_rf").value*1;
    var alfa_h0 = document.getElementById("alfa_h0").value*1;
    var epsilon_deltaR_h0 = document.getElementById("epsilon_deltaR_h0").value*1;
    var kt = document.getElementById(element + "_k_" + number).value*1; //U-factor
    var s = document.getElementById(element + "_s_" + number).value*1; //Area of element
    var tin = document.getElementById("tin").value*1;
    var te = new Array();
     qii = new Array();
	var qbi = new Array();
	var qdi = new Array();
	var qci = new Array();
	var qdci_c = new Array();
	var qdci_r = new Array();
	var qdci_r_RTS = new Array();
	var qdci_t = new Array();
	var qbdci_t = new Array();
    qh_CTS = new Array();
    qh_RTS = new Array();
	var qbi_RTS = new Array();
	
    //cooling_load_walls[number_wall] = new Array();

	//alert(CTS[1]);

 d.length = 0;   



//Titles for table colums
        d[0] = "Local Standart Hour_Локальное время";
        d[1] = "Total Surface Irradiance_Полная радиация, W/m2";
        d[2] = "Outside Temp. C_Температура наружнего воздуха";
        d[3] = "Sol-Air Temp. C_Солнечно-воздушная температура";
        d[4] = "Inside Temp. C_Температура внутри помещения";
        d[5] = "Heat input, W_Полученное тепло";
        d[6] = "CTS Type1, %_Конвективная инерционность";
        d[7] = "Heat Gain Total, W_Суммарное переданное тепло";
        d[8] = "Heat Gain Convective, W_Тепло переданное конвекцией";
        d[9] = "Heat Gain Radiant, W_Тепло переданное радиацией";
        d[10] = "Nonsolar RTS Zone %_Радиационная инерционность";
        d[11] = "Radiant Cooling Load, W_Радиационная охлаждающая нагрузка";
        d[12] = "Total Cooling Load, W_Суммарная охлаждающая нагрузка";

if (element == "wall") {
    if (document.getElementById("replace_"+element+ "_" + number +"_CTS").innerHTML == "<u>Выбор стены...</u>")
	{alert ("Выберете Стену");
	}
	else {
	    CTS = read_from_base_CTS(element,number).split(" ");
	
	for (var i=1; i<=24; i++){//Calculate heat input profile
    var myrad = new radiation(day_number, i, latitude, longitude, zone, psi, tilt, taub, taud, gr_rf, '', alfa_h0, epsilon_deltaR_h0); 
    
	
	if (mysun_on_plane.aST>=0){ //verify with another calculate

    t_hour[i] = tout_design - fraction_t_array[(mysun_on_plane.aST).toFixed(0)*1+1]*tout_range;   }
    else {    t_hour[i] = tout_design - fraction_t_array[25 + (mysun_on_plane.aST).toFixed(0)*1]*tout_range;   }

	var myrad = new radiation(day_number, i, latitude, longitude, zone, psi, tilt, taub, taud, gr_rf, t_hour[i], alfa_h0, epsilon_deltaR_h0); 
	qii[i] = kt * s *(myrad.te - tin);
	}
   	//Calculate heat gain using conductive time series
	qh_CTS = get_q_xts(qii,CTS);

	//Calculate heat gain using radiant time series
	qh_RTS = get_q_xts(qh_CTS,RTS_array);

	for (var n=1; n<=24; n++){//Calculate radian portion of the cooling
	var myrad = new radiation(day_number, n, latitude, longitude, zone, psi, tilt, taub, taud, gr_rf, t_hour[n], alfa_h0, epsilon_deltaR_h0);
     h_string +=  "<tr><td>" + n + "</td><td>" + myrad.et.toFixed(1) + "</td><td>" + t_hour[n].toFixed(1) + "</td><td>" + myrad.te.toFixed(1) + "</td><td>" +tin+ "</td><td>"  +qii[n].toFixed(0)+"</td><td>" +CTS[n-1] + "</td><td>" + qh_CTS[n].toFixed(0) + "</td><td>" +(qh_CTS[n]*0.54).toFixed(0) + "</td><td>" + (qh_CTS[n]*0.46).toFixed(0) + "</td><td>" + RTS_array[n-1] + "</td><td>" + (qh_RTS[n]*0.46).toFixed(0) + "</td><td>" + (qh_CTS[n]*0.54+qh_RTS[n]*0.46).toFixed(0) + "</td></tr>";
	//cooling_load_walls[number_wall][n] = (qh_CTS[n]*0.54+qh_RTS[n]*0.46);
	}

	if (table){
	
		bottom_line = "<td></td><td><input type=button value=График onclick=\"drawChart('radiation','et','"+element+"',"+number+",'"+d[1].split("_")[0]+"','radiation')\"><div id = dialog_" + element+ "_" + number +"_et_graph1><div id = " + element+ "_" + number +"_et_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart(t_hour,'t_hour','"+element+"',"+number+",'"+d[2].split("_")[0]+"','radiation')\"><div id = dialog_" + element+ "_" + number +"_t_hour_graph1><div id = " + element+ "_" + number +"_t_hour_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart('radiation','te','"+element+"',"+number+",'"+d[3].split("_")[0]+"','radiation')\"><div id = dialog_" + element+ "_" + number +"_te_graph1><div id = " + element+ "_" + number +"_te_graph2></div></div></td><td></td><td><input type=button value=График onclick=\"drawChart(qii,'qii','"+element+"',"+number+",'"+d[5].split("_")[0]+"','radiation')\"><div id = dialog_" + element+ "_" + number +"_qii_graph1><div id = " + element+ "_" + number +"_qii_graph2></div></div></td><td></td><div id = " + element+ "_" + number +"_CTS_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart(qh_CTS,'qh_CTS','"+element+"',"+number+",'"+d[7].split("_")[0]+"','radiation')\"><div id = dialog_" + element+ "_" + number +"_qh_CTS_graph1><div id = " + element+ "_" + number +"_qh_CTS_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart(qh_CTS,'qh_CTSconv','"+element+"',"+number+",'"+d[8].split("_")[0]+"','radiation',"+0.54+")\"><div id = dialog_" + element+ "_" + number +"_qh_CTSconv_graph1><div id = " + element+ "_" + number +"_qh_CTSconv_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart(qh_CTS,'qh_CTSrad','"+element+"',"+number+",'"+d[9].split("_")[0]+"','radiation',"+0.46+")\"><div id = dialog_" + element+ "_" + number +"_qh_CTSrad_graph1><div id = " + element+ "_" + number +"_qh_CTSrad_graph2></div></div></td><td></td><td><input type=button value=График onclick=\"drawChart(qh_RTS,'qh_RTS','"+element+"',"+number+",'"+d[11].split("_")[0]+"','radiation',"+0.46+")\"><div id = dialog_" + element+ "_" + number +"_qh_RTS_graph1><div id = " + element+ "_" + number +"_qh_RTS_graph2></div></div></td><td><input type=button value=График onclick=\"drawChart(qh_CTS,'qh_RTSCTS','"+element+"',"+number+",'"+d[12].split("_")[0]+"','radiation',0.54,qh_RTS,0.46)\"><div id = dialog_" + element+ "_" + number +"_qh_RTSCTS_graph1><div id = " + element+ "_" + number +"_qh_RTSCTS_graph2></div></div></td>";
		
		
	document.getElementById("Table_qii").innerHTML = "<table border = 1>"+create_table_titles(d)+""+h_string+"<tr>" + bottom_line + "</tr></table>";
	}
	}
	}
	
	
 if (element =="window") {
	var shgc_d = document.getElementById(element + "_shgc_d_" + number).value*1;
	var iac = document.getElementById(element + "_iac_" + number).value*1;
		for (var i=1; i<=24; i++){//Calculate heat input profile
		var mysun = new sun_on_plane(day_number, i, latitude, longitude,zone, psi,tilt); 	
		var myrad = new radiation(day_number, i, latitude, longitude, zone, psi, tilt, taub, taud, gr_rf, t_array[i-1], alfa_h0, epsilon_deltaR_h0); 
		var shgc_fi = interpolate(mysun.Fi, SHGC_fi);//get shgc(fi) value for current surface incidence angle (Fi)
		qbi[i] = s * myrad.etb * shgc_fi * iac; //beam solar heat
		qdi[i] = s * (myrad.etd + myrad.etr) * shgc_d * iac; //diffuse solar heat gain
		qci[i] = kt * s * (t_array[i-1] - tin); //conduction heat gain
		qdci_c[i] = (qdi[i] + qci[i])*0.54;  //convection part of totaled diffuse and conductive gains
		qdci_r[i] = (qdi[i] + qci[i])*0.46;  //radiant part of totaled diffuse and conductive gains
	}
	//Calculate beam cooling load using RTS of 100% beam radiation, diffuse and conductive summarize and split into radiant and convective portion: for SHGC>0.5 -> R0.33, C0.67, SHGC<0.5 -> R0.46, C0.54. 
	qbi_RTS = get_q_xts(qbi,RTS_array_2); //beam solar heat with RTS factor
	qdci_r_RTS = get_q_xts(qdci_r,RTS_array); //radiant part of totaled diffuse and conductive gains with RTS factor	
	for (var i=1; i<=24; i++){
	 qdci_t[i] = qdci_c[i] + qdci_r_RTS[i];//summ convective and radiant parts of diffuse and conductive gain
	 qbdci_t[i] = qdci_t[i] + qbi_RTS[i]; //summ diffuse, beam and conductive heat gains
	 }
	 alert (qbdci_t[14] + "  " + qdci_t[14] + " " + qdci_r_RTS[14] + " " + qdci_c[14]);// + "  " + qci[15]);
	
}
}



function total_cooling_load_wall(){

    var total_load = new Array();
    var h_string = button_wall_cooling_load
       for (var n=1; n<=24; n++){
     total_load[n] = 0;   
    for (var i=1; i<=quantity_wall_js; i++){
        
        cooling_load_wall(i,0);
    total_load[n] = total_load[n] + cooling_load_walls[i][n];

    }
    }
    for (var k=1; k<=24; k++){
        h_string += "<tr><td>" + k + "</td><td>" + total_load[k].toFixed(2) + "</td></tr>";
    }
         d.length = 0; 


//Titles for table colums
        d[0] = "Local Standart Hour_Локальное время";
        d[1] = "Total Cooling Load, W_Суммарная охлаждающая нагрузка, Вт";
        
    document.getElementById("Table_qii").innerHTML =  "<table border = 1>"+create_table_titles(d)+"" + h_string + "</table>" ;
}


        
        
        

        
        
        
    


</script> 



<style type="text/css"> 


.notsee {position: relative; display: none;}
.nowsee {position: relative; display: block; cursor:default;}
.see {position: relative; width:300; cursor:pointer; list-style-type: none;}

 #map_canvas {
      width: 500px;
      height: 300px;
}

 #input {
      margin: 25px;
list-style: none;
}

 .contextmenu{
    visibility:hidden;
    background:#ffffff;
    border:1px solid #8888FF;
    z-index: 10;  
    position: relative;
    width: 100px;
}
}
</style> 
</head>
<body> 

<b> Общие данные<b>

<table border = "1">
<tr>
<td> Местоположение</td>
<td><input id="address_st" type="textbox" value="Москва" onchange="codeAddress(this.value)" ></td> 
<td rowspan="4">
<div id="map_canvas"></div>
</td> 
</tr>
<tr> 
<td>Широта</td>
<td><input id="latitude" type="textbox" value="33.64" onchange="calc_E0()"> </td>
</tr>
<tr>
<td>Долгота</td>
<td> <input id="longitude" type="textbox" value="-84.43" onchange="calc_E0()"> </td>
</tr>
<tr>
<td>Высота</td>
<td> <div id="elevation"></div> </td>
</tr>
<tr>
<td>День в году </td>
<td> <input id="day_number" type="textbox" value="202" onchange="calc_E0()"></td> 
<td><a href = # onClick="initialize()"/>Использовать карту</a></td>
</tr>
<tr>
<td>Локальное время </td>
<td> <input id="LST" type="textbox" value="15" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>Временная зона </td>
<td> <input id="zone" type="textbox" value="-5" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>Taub</td>
<td> <input id="taub" type="textbox" value="0.556" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>Taud</td>
<td> <input id="taud" type="textbox" value="1.779" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>Отражательная способность земли</td>
<td> <input id="gr_rf" type="textbox" value="0.2" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>alfa/ho</td>
<td> <input id="alfa_h0" type="textbox" value="0.053" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>epsilon*deltaR/h0</td>
<td> <input id="epsilon_deltaR_h0" type="textbox" value="0" onchange="calc_E0()"></td> 
</tr>
<tr>
<td>Месячная температура по сухому термометру</td>
<td> <input id="tout" type="textbox" value="33.3"></td> 
</tr>
<tr>
<td>Месячный температурный диапазон</td>
<td> <input id="tout_range" type="textbox" value="11.5"></td> 
</tr>
<tr>
<td>Температура внутри помещения </td>
<td> <input id="tin" type="textbox" value="23.9" onchange="calc_E0()"></td> 
</tr>
</table>
<div id= "wall"></div>
<div id= "window"></div>
<div id= "roof"></div>
<div id= "floor"></div>


<input type="radio"  name="group1" value="Solar_irradiance" onclick="solar_irradiance_select()" checked> Солнечная радиация
<input type="radio" name="group1" value="Cooling_load" onclick="cooling_load_element_select()"> Нагрузки
<input type="button" value="Стена" onclick="add_element(1,'wall')">
<input type="button" value="Окно" onclick="add_element(1,'window')">
<a href=#  onClick="select_language('ru')">Ru</a> <a href=#  onClick="select_language('en')"> En </a>
<div id="Table_qii"></div>
<div id="info"></div>
<input id="number" size=1% type="textbox" value="1" >


</body> 
</html>